<?php
namespace common\models;

use Yii;
use common\models\base\BaseModel;

/**
 * This is the model class for table "post_extends".
 *
 * @property integer $id
 * @property integer $post_id
 * @property integer $browser
 * @property integer $collect
 * @property integer $praise
 * @property integer $comment
 */
class PostExtendsModel extends BaseModel
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'post_extends';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'post_id',
                    'browser',
                    'collect',
                    'praise',
                    'comment'
                ],
                'integer'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'post_id' => '文章编号',
            'browser' => '浏览量',
            'collect' => 'Collect',
            'praise' => 'Praise',
            'comment' => 'Comment'
        ];
    }

    /**
     * 显示文章浏览数量
     * @param unknown $cond
     * @param unknown $attribute
     * @param unknown $num
     */
    public function upCounter($cond, $attribute, $num)
    {
        $counter = $this->findOne($cond);
        if (! $counter) {
            $this->setAttributes($cond);
            $this->$attribute = $num;
            $this->save();
        } else {
            $countData[$attribute] = $num;
            $counter->updateCounters($countData);
        }
    }
}
